package com.smart.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.smart.entity.DeviceType;
import com.smart.entity.vo.DeviceSubTypeVo;
import com.smart.entity.vo.DeviceTypeVo;
import com.smart.mapper.DeviceTypeMapper;
import com.smart.service.IDeviceTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <p>
 * 设备类型表 服务实现类
 * </p>
 *
 * @author Cookies
 * @since 2024-05-31
 */
@Service
public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceType> implements IDeviceTypeService {
    @Override
    public Set<DeviceTypeVo> getDeviceAllTypeList() {
        List<DeviceType> deviceTypeList = lambdaQuery().select(DeviceType::getType, DeviceType::getTypeName).list();
        List<DeviceTypeVo> deviceTypeVoList = BeanUtil.copyToList(deviceTypeList, DeviceTypeVo.class);
        Set<DeviceTypeVo> typesSet = new LinkedHashSet<>(deviceTypeVoList);
        return typesSet;
    }

    @Override
    public List<DeviceSubTypeVo> getDeviceSubTypeListByType(String type) {
        List<DeviceType> deviceTypeList = lambdaQuery().select(DeviceType::getSubType, DeviceType::getSubTypeName)
                .eq(DeviceType::getType, type)
                .list();
        List<DeviceSubTypeVo> deviceSubTypeVoList = BeanUtil.copyToList(deviceTypeList, DeviceSubTypeVo.class);
        return deviceSubTypeVoList;
    }
}
